package com.example.exception;

import com.example.demoproject.common.BaseResponse;
import com.example.demoproject.common.ErrorCode;
import com.example.demoproject.utils.ResultUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * @author TheOutsider
 */
@RestControllerAdvice
@Slf4j
public class GlobalExceptionHandler {

    @ExceptionHandler(OrderException.class)
    public BaseResponse orderExceptionHandler(OrderException exception) {
        log.error("OrderException: " + exception.getMessage(), exception.getDescription());
        return ResultUtils.error(exception.getCode(), exception.getMessage(), exception.getDescription());
    }

    @ExceptionHandler(RuntimeException.class)
    public BaseResponse runtimeExceptionHandler(RuntimeException exception) {
        return ResultUtils.error(ErrorCode.SYSTEM_ERROR, exception.getMessage(), "");
    }

}
